#
# 这里仅移植了aircrack-ng工具，如果需要其它工具的构建可以根据此文件和源码中的makefile仿写
# 如果需要重新配置相关模块可以在linux上配置好，覆盖这里的config.h(可能需要添加其它依赖，如sqlite)
# 这里使用的配置为：
#	./configure \
#	--with-experimental \
#	--enable-static=yes \
#	--host=arm-linux-androideabi \
#	--prefix=/data/local/tmp \
#	--with-sysroot=${SYSROOT} \
#	--with-openssl=${LIBS_DIR}/openssl
#
# 注： 有对源码极小范围的修改

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LIB_DIR := lib
OSDEP_INCLUDES = $(LOCAL_PATH)/include/aircrack-ng/osdep

OSDEP_SRC      = $(LIB_DIR)/osdep/osdep.c \
                 $(LIB_DIR)/osdep/network.c \
                 $(LIB_DIR)/osdep/file.c \
                 $(LIB_DIR)/osdep/linux.c \
                 $(LIB_DIR)/osdep/linux_tap.c \
                 $(LIB_DIR)/osdep/common.c

RADIOTAP_SRC = $(LIB_DIR)/radiotap/radiotap.c

# $(COMMON_CFLAGS) $(PCRE_CFLAGS) \

# 实际添加了-DSTATIC_BUILD之后这些应该都无所谓，这些路径也应当是linux下的绝对路径
# 这里仅标识成源码的相对路径，如果需要使用动态库需要修改此部分(ce-wpa和osdep库)
LA_CFLAGS = -DLIBAIRCRACK_CE_WPA_PATH=\"build\" \
	        -DABS_TOP_SRCDIR=\"src\" \
	        -DABS_TOP_BUILDDIR=\"build\" \
	        -DLIBDIR=\"lib\" \
	        -DSTATIC_BUILD

LA_SRC = $(LIB_DIR)/libac/adt/avl_tree.c \
	     $(LIB_DIR)/libac/adt/circular_buffer.c \
	     $(LIB_DIR)/libac/adt/circular_queue.c \
	     $(LIB_DIR)/libac/cpu/simd_cpuid.c \
	     $(LIB_DIR)/libac/support/fragments.c \
	     $(LIB_DIR)/libac/support/common.c \
	     $(LIB_DIR)/libac/support/communications.c \
	     $(LIB_DIR)/libac/support/crypto_engine_loader.c \
	     $(LIB_DIR)/libac/support/mcs_index_rates.c \
	     $(LIB_DIR)/libac/tui/console.c \
	     $(LIB_DIR)/libac/utf8/verifyssid.c \
	     $(LIB_DIR)/libac/cpu/trampoline_arm.c \
	     $(LIB_DIR)/libac/cpu/cpuset_pthread.c

#	     $(LIB_DIR)/libac/cpu/trampoline_ppc.c \
#	     $(LIB_DIR)/libac/cpu/trampoline_x86.c \
#	     $(LIB_DIR)/libac/cpu/trampoline_stubs.c \
#	     $(LIB_DIR)/libac/cpu/cpuset_hwloc.c


CRYPTO_SRC = $(LIB_DIR)/crypto/crypto.c

#             $(LIB_DIR)/crypto/sha1-git.c \
#             $(LIB_DIR)/crypto/sha1-sse2.S

CE_WEP_SRC = $(LIB_DIR)/ce-wep/uniqueiv.c

CE_WPA_SRC = $(LIB_DIR)/ce-wpa/crypto_engine.c \
			 $(LIB_DIR)/ce-wpa/memory.c \
			 $(LIB_DIR)/ce-wpa/simd-intrinsics.c \
			 $(LIB_DIR)/ce-wpa/wpapsk.c

PTW_SRC = $(LIB_DIR)/ptw/aircrack-ptw-lib.c


SRC_DIR := src

SRC_LINECOUNT	= $(SRC_DIR)/aircrack-ng/linecount.cpp

SRC_AC			= $(SRC_DIR)/aircrack-ng/aircrack-ng.c
SRC_AD			= $(SRC_DIR)/airdecap-ng/airdecap-ng.c
SRC_PF			= $(SRC_DIR)/packetforge-ng/packetforge-ng.c
SRC_AR			= $(SRC_DIR)/aireplay-ng/aireplay-ng.c
SRC_ADU			= $(SRC_DIR)/airodump-ng/airodump-ng.c

SRC_AT			= $(SRC_DIR)/airtun-ng/airtun-ng.c
SRC_IV			= $(SRC_DIR)/ivstools/ivstools.c
SRC_AS			= $(SRC_DIR)/airserv-ng/airserv-ng.c
SRC_WS			= $(SRC_DIR)/wesside-ng/wesside-ng.c
SRC_BS			= $(SRC_DIR)/besside-ng/besside-ng.c
SRC_BC			= $(SRC_DIR)/besside-ng-crawler/besside-ng-crawler.c
SRC_AL			= $(SRC_DIR)/airolib-ng/airolib-ng.c
SRC_KS			= $(SRC_DIR)/kstats/kstats.c
SRC_ES			= $(SRC_DIR)/easside-ng/easside-ng.c
SRC_BUDDY		= $(SRC_DIR)/buddy-ng/buddy-ng.c
SRC_MI			= $(SRC_DIR)/makeivs-ng/makeivs-ng.c
SRC_AB			= $(SRC_DIR)/airbase-ng/airbase-ng.c
SRC_AU			= $(SRC_DIR)/airdecloak-ng/airdecloak-ng.c
SRC_TT			= $(SRC_DIR)/tkiptun-ng/tkiptun-ng.c
SRC_WC			= $(SRC_DIR)/wpaclean/wpaclean.c
SRC_AV			= $(SRC_DIR)/airventriloquist-ng/airventriloquist-ng.c
SRC_SESSION	= $(SRC_DIR)/aircrack-ng/session.c
SRC_DWRITE	= $(SRC_DIR)/airodump-ng/dump_write.c

#bin_PROGRAMS += aircrack-ng \
#                airdecap-ng \
#                packetforge-ng \
#                ivstools \
#                kstats \
#                makeivs-ng \
#                airdecloak-ng
#
#if EXPERIMENTAL
#if HAVE_PCAP
#bin_PROGRAMS += besside-ng-crawler
#endif
#endif
#
#bin_PROGRAMS += wpaclean
#
#sbin_PROGRAMS += airbase-ng \
#                 aireplay-ng \
#                 airodump-ng \
#                 airserv-ng \
#                 airtun-ng
#
#if HAVE_SQLITE3
#bin_PROGRAMS += airolib-ng
#endif
#
#if EXPERIMENTAL
#bin_PROGRAMS += buddy-ng
#
#sbin_PROGRAMS += airventriloquist-ng
#
#if HAVE_AIRPCAP_OR_PCAP
#sbin_PROGRAMS += besside-ng \
#                 easside-ng \
#                 tkiptun-ng \
#                 wesside-ng
#endif
#endif

aircrack_ng_SOURCES		= $(SRC_AC) $(SRC_LINECOUNT) $(SRC_SESSION)
aircrack_ng_CFLAGS		= $(COMMON_CFLAGS) $(SQLITE3_CFLAGS) $(LIBPTW_CFLAGS)
aircrack_ng_CPPFLAGS	= $(AM_CPPFLAGS) -I$(SRC_DIR)/aircrack-ng
aircrack_ng_LDADD		= $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) $(LIBAIRCRACK_CE_WEP_LIBS) $(SQLITE3_LDFLAGS) $(SQLITE3_LIBS) $(LIBPTW_LIBS) $(COMMON_LDADD) $(CRYPTO_LIBS) $(HWLOC_LIBS)

#if STATIC_BUILD
aircrack_ng_CFLAGS		+= -DDYNAMIC=0
aircrack_ng_LDADD		+= $(LIBAIRCRACK_CE_WPA@SIMD_SUFFIX@_LIBS)
#else
#aircrack_ng_LDFLAGS		= -rdynamic
#endif

airdecap_ng_SOURCES	= $(SRC_AD)
airdecap_ng_CFLAGS	= $(COMMON_CFLAGS) $(CRYPTO_CFLAGS)
airdecap_ng_LDADD	= $(LIBACCRYPTO_LIBS) $(COMMON_LDADD) $(LIBAIRCRACK_LIBS) $(CRYPTO_LDFLAGS) $(CRYPTO_LIBS)



include $(CLEAR_VARS)
LOCAL_MODULE    := nl
LOCAL_SRC_FILES := $(LOCAL_PATH)/../nl/lib/libnl-3.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := nl-genl
LOCAL_SRC_FILES := $(LOCAL_PATH)/../nl/lib/libnl-genl-3.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := crypto
LOCAL_SRC_FILES := $(LOCAL_PATH)/../openssl/lib/libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := ssl
LOCAL_SRC_FILES := $(LOCAL_PATH)/../openssl/lib/libssl.so
include $(PREBUILT_SHARED_LIBRARY)

#include $(CLEAR_VARS)
#LOCAL_MODULE := aircrack-osdep
#LOCAL_SRC_FILES :=
#include $(LOCAL_STATIC_LIBRARIES)


include $(CLEAR_VARS)
# -w 去除所有的编译警告消息
LOCAL_CFLAGS     += -w -DHAVE_CONFIG_H $(LA_CFLAGS)
LOCAL_LDLIBS     := -llog
LOCAL_SHARED_LIBRARIES := ssl crypto
LOCAL_STATIC_LIBRARIES := nl nl-genl

LOCAL_MODULE     := aircrack-ng
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../openssl/include \
                    $(LOCAL_PATH)/../nl/include/libnl3 \
                    $(LOCAL_PATH)/lib \
                    $(OSDEP_INCLUDES) \
                    $(LOCAL_PATH)/include

LOCAL_SRC_FILES  := $(OSDEP_SRC) \
                    $(RADIOTAP_SRC) \
                    $(LA_SRC) \
                    $(CRYPTO_SRC) \
                    $(CE_WPA_SRC) \
                    $(CE_WEP_SRC) \
                    $(PTW_SRC) \
                    $(aircrack_ng_SOURCES)

#                    $(SRC_AB) \
#                    jni.c

#include $(BUILD_SHARED_LIBRARY)
# 生成可执行文件
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
